<template>
  <div>
    <div class="table-component">
      <div class="row">
        <div class="row information">
          <div>车牌号:{{ operationId.licensePlate }}</div>
          <div style="margin-left: 55px">手机号码:{{ operationId.phone }}</div>
        </div>

        <div class="submit-btns">
          <el-button
            type="primary"
            class="submit-btn-export"
            @click="exportData"
          >
            <img class="icon-img" :src="iconExport" alt="" />导出</el-button
          >
        </div>
      </div>
    </div>
    <div class="table">
      <el-table
        :data="table.data"
        :loading="table.loading"
        style="width: 100%"
        :header-cell-style="{
          background: '#F1F1F1',
          'font-size': '14px',
          'font-weight': 600,
          color: '#333333',
        }"
        :cell-style="{
          'font-size': '14px',
          'font-weight': 400,
          color: '#333333',
        }"
      >
        <!-- <el-table-column label="序号" min-width="60" fixed="left">
          <template #default="scope">
            {{ (scope.$index + 1).toString().padStart(2, "0") }}
          </template>
        </el-table-column> -->
        <el-table-column prop="id" label="订单编号" min-width="160" />
        <el-table-column prop="toBePaid" label="待付金额(元)" min-width="100" />
        <el-table-column prop="berthCode" label="泊位号" min-width="70" />
        <el-table-column prop="section" label="路段名称" min-width="90" />
        <el-table-column prop="canton" label="所属行政区" min-width="90" />
        <el-table-column prop="duration" label="停车时长" min-width="120" />
        <el-table-column prop="inTime" label="驶入时间" min-width="140" />
        <el-table-column prop="outTime" label="驶出时间" min-width="140" />
        <el-table-column prop="checkWay" label="登记方式">
          <template #default="scope">
            {{
              scope.row.checkWay == 1
                ? "PDA"
                : scope.row.checkWay == 2
                ? "高位视频"
                : "视频桩"
            }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination">
      <el-pagination
        v-model:current-page="pagination.currentPage"
        v-model:page-size="pagination.pageSize"
        :page-sizes="pagination.pageSizes"
        layout="total,sizes, prev, pager, next, jumper"
        :total="table.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import iconExport from "@/assets/image/btn/icon-export.png";
import { getPendingPaymentOrders } from "../request.js";

const props = defineProps({
  operationId: {
    type: Object,
    default: () => {},
  },
});

// 表格
const table = reactive({
  data: [],
  total: 0,
  loading: true,
});

const pagination = reactive({
  currentPage: 1,
  pageSize: 10,
  pageSizes: [10, 20, 30, 50],
});

const handleCurrentChange = (value) => {
  pagination.currentPage = value;
  getData();
};

const handleSizeChange = (value) => {
  pagination.pageSize = value;
  getData();
};

const getData = async () => {
  await getPendingPaymentOrders({
    keyword: props.operationId.licensePlate,
    pageNo: pagination.currentPage,
    pageSize: pagination.pageSize,
  }).then((res) => {
    if (res.data.code === 0) {
      table.data = res.data.result.items;
      table.total = parseInt(res.data.result.total);
      table.loading = false;
    }
  });
};

getData();
</script>

<style lang="less" scoped>
.table-component {
  margin-bottom: 24px;
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.information {
  font-weight: 600;
  font-size: 14px;
  color: #333333;
}
.submit-btns {
  display: flex;
  justify-content: space-between;
  .submit-btn-export {
    background: #35c362;
    border: 1px solid #35c362;
    border-radius: 2px;
    margin-left: 12px;
    padding: 5px 16px;
  }
  .icon-img {
    width: 16px;
    height: 16px;
    margin-right: 8px;
  }
}
.table {
  margin-bottom: 15px;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>